<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
      <head>
            <title><?php the_title(); ?> &laquo; <?php site_name(); ?></title>
            <link rel="stylesheet" type="text/css" href="<?php theme_stylesheet(); ?>" />
            <script type="text/javascript" src="<?php theme_path(); ?>/js/jquery.js"></script>
            <script type="text/javascript" src="<?php theme_path(); ?>/js/json2.js"></script>
            <script type="text/javascript" src="<?php theme_path(); ?>/js/+core.js"></script>
            <script type="text/javascript">
            $(document).ready( function () {
                  Core.local.insertEvents();
                  Core.local.folder = "<?php site_folder(); ?>/";
                  Core.steamNavbar.make({
                        sections: {
                              "My Query": {
                                    'Query' : {
                                          'id': 'navbar-query-content'
                                    },
                                    "Log": {
                                          "id": "navbar-log-content"
                                    },
                                    "prototypes": {
                                          "id": "navbar-prototypes-content"
                                    }
                              },
                              "Users & articles": {
                                    "Relate them": {
                                          "reference": {
                                                "title": "Articles",
                                                "references": {
                                                <?php 
                                                $articles = $query->prototypes->article->getElements();
                                                $i = 0;
                                                foreach ($articles as $article) { ?>
"<?php echo $article->title; ?>": {
                                                            "id": <?php echo $article->id; ?>,
                                                            "type": "<?php echo $article->_type; ?>"<?php 
                                                            $relations = $article->getMembers('user');
                                                            $e = 0;
if ($relations) { ?>,
                                                            "relations": [
                                                            <?php foreach ($relations as $relation) {  ?>
                                                                  {
                                                                        "id": "<?php echo $relation->{$relation->_roles['id']}; ?>",
                                                                        "type": "<?php echo $relation->_type; ?>",
                                                                        "relationship": "<?php echo $relation->_relationship; ?>"
                                                                  }<?php if ($e + 1 != count($relations)) { ?>,<?php }
                                                            $e ++;
} ?>                                                            ]
                                                            <?php }     
                                                            ?>      
                                                      }<?php if ($i + 1 != count($articles)) { ?>,<?php } 
                                                      $i ++;
                                                } ?>
                                                }
                                          },
                                          "resources": {
                                                "title": "Users",
                                                "resources": {
<?php 
      $users = $query->prototypes->user->getElements();
      $i = 0;
      foreach ($users as $user) { 
      ?>
                                                      "<?php echo $user->name; ?>": {
                                                            "id": <?php echo $user->id; ?>,
                                                            "type": "<?php echo $user->_type; ?>"
                                                      }<?php if ($i + 1 != count($users)) { ?>,<?php } ?>
<?php 
      $i ++;
      } ?>                                                    
                                                }
                                          },
                                          "relations": [<?php 
                                                $i = 0;
                                                foreach ($query->profiles as $profile => $things) {
                                                      if (substr($profile, 0, 1) != "_") {
                                                      ?>
                                                      "<?php echo $profile; ?>"<?php if ($i + 1 != count($query->profiles)) { ?>,<?php }
                                                      }
                                                      $i ++;
                                                }
                                                ?>
                                          ]
                                    }
                              }
                        }
                  });

            });
            </script>
      </head>
      <body>
            <div id="steam-hidden" style="display: none;">
                  <div id="navbar-query-content">
                        <?php $ar->query = $query; dump_to_xhtml($ar); ?>
                  </div>
                  <div id="navbar-log-content">
                        <?php $er->log = $query->log; dump_to_xhtml($er); ?>
                  </div>
                  <div id="navbar-prototypes-content">
                        <?php $ir->prototypes = $query->prototypes; dump_to_xhtml($ir); ?>
                  </div>
            </div>
            <a href="<?php site_url(); ?>"><h1 id="header"></h1></a>
            <div id="menu">
                  <a href="query"<?php if (is_section('query')) { ?> class="the-chosen-one"<?php } ?>>
                        Query
                  </a>
                  <a href="prototypes"<?php if (is_section('prototypes')) { ?> class="the-chosen-one"<?php } ?>>
                        prototypes
                  </a>
                  <a href="function-testing"<?php if (is_section('function-testing')) { ?> class="the-chosen-one"<?php } ?>>
                        Function Testing
                  </a>                  
                  
            </div>
            <div class="clearer"></div>
            <div id="wrap">